cc.Class({
    extends: cc.Component,

    properties: {
        Bg0: cc.Node,
        Bg1: cc.Node,
        Label: cc.Label,
        // circle:cc
    },
    ctor:function(){
        this.m_Hp =20;
        this.isDie =false;
        this.position ={};
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.Bg0.runAction(cc.repeatForever(cc.rotateBy(5, 360)));
        this.Bg1.runAction(cc.repeatForever(cc.rotateBy(5, -360)));
        this.init();

    },

    onCollisionEnter: function(other, self) {
        // console.log('on collision stay',other.node);
        if (other.tag === 1) { //0是病毒

            this.hit();
        }


    },
    init(){

        this.setHp( this.m_Hp);
        this.setColor(new cc.color(127,137,245));
        this.speedx = random(100,150);
        this.speedy =random(50,120);
        this.position.x = random(150,750);
        this.position.y = 1700;
        this.node.setPosition(this.position.x,this.position.y);

    },
    setColor(color){
        this.node.color = color;
        setVirusColor(this.node,color);
    },
    hit(){
        if(this.isDie)return;
        // eslint-disable-next-line camelcase
        this.m_Hp -=1;
        this.setHp(this.m_Hp);
        if (this.m_Hp <= 0) {
            console.log('die----------------', this.m_Hp);
            this.isDie = true;
            virusMake.onKillVirus(this.node);
            virusMake.createDieAnima(this.node);

        }
        this.hurt();

    },
    hurt(){
        let notplay = false;
        if (!notplay) {
            let goldSeq = cc.sequence(
                cc.scaleTo(0.05, 1.1, 1.1),
                cc.delayTime(0.01),
                cc.scaleTo(0.05, 0.9, 0.9),
                cc.callFunc(function() {
                    notplay = false;
                }));
            this.node.runAction(goldSeq);
        }

    },
    playOver() {
        console.log('播放完毕');
        this.node.runAction(cc.scaleTo(0.08, 0, 0));
        this.node.active = false;
    },

    update(dt) {
        this.node.y -= dt * this.speedy;
        this.node.x +=dt*this.speedx;
        if(this.node.x>750||this.node.x<150){
            this.speedx *= -1;
        }
        if(this.node.y<0){
            this.position.x = random(150,750);
            this.position.y = 1700;
            this.node.setPosition(this.position.x,this.position.y);
        }
    },
    //setHep
    setHp(num) {
        this.Label.string = num;
    },
});